package com.stenio.fancat.controller.user;

import com.stenio.fancat.controller.Result;
import com.stenio.fancat.domain.user.UserIconImage;
import com.stenio.fancat.form.user.UserIconImageForm;
import com.stenio.fancat.service.user.UserIconImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author sunweijia
 * @date 2018/12/1
 * @desc
 **/
@RestController
@RequestMapping("user/image")
public class UserIconImageController {

    @Autowired
    private UserIconImageService userIconImageService;

    /**
     * 上传图片（头像）
     * @param multipartFile
     * @param userIconImageForm
     * @return
     */
    @PostMapping("upload")
    public Result<UserIconImage> upload(MultipartFile multipartFile,
                                        @RequestBody UserIconImageForm userIconImageForm){
        Result<UserIconImage> result = new Result();
        result.setData(userIconImageService.insertUserIconImageByCondition(multipartFile,userIconImageForm));
        result.setFlag(Result.FLAG.success);
        return result;
    }

    /**
     * 修改图片（头像）
     * @param multipartFile
     * @param userIconImageForm
     * @return
     */
    @PostMapping("update")
    public Result<UserIconImage> update(MultipartFile multipartFile,
                                        @RequestBody UserIconImageForm userIconImageForm){
        Result<UserIconImage> result = new Result();
        result.setData(userIconImageService.modifyUserIconImageByCondition(multipartFile,userIconImageForm));
        result.setFlag(Result.FLAG.success);
        return result;
    }

    /**
     * 查询图片（头像）
     * @param userIconImageForm
     * @return
     */
    @PostMapping("select")
    public Result<UserIconImage> select (@RequestBody UserIconImageForm userIconImageForm){
        Result<UserIconImage> result = new Result();
        result.setData(userIconImageService.queryUserImageByCondition(userIconImageForm.getUserId()));
        result.setFlag(Result.FLAG.success);
        return result;
    }
}
